﻿using MikuMikuLibrary.Archives.Farc;
using MikuMikuLibrary.Databases;
using MikuMikuLibrary.Sprites;
using MikuMikuLibrary.Textures;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ft_module_parser.sprutilities
{
    static class sprselpv
    {
        public static void Make()
        {
            Console.WriteLine("Image to spr_sel_pv v1");
            Console.WriteLine(textconst.credits);
            Console.WriteLine();
            
            Bitmap source = null;
            Bitmap source2 = null;
            Bitmap source3 = null;
            SpriteDatabase spritedb = new SpriteDatabase();

            OpenFileDialog openFileDialog1;

            int id = -1;
            bool parsed = false;
            while (parsed == false)
            {   
                Console.Write("PVID? > ");
                parsed = int.TryParse(Console.ReadLine(), out id);
            }

            openFileDialog1 = new OpenFileDialog
            {
                Title = "Browse Image (0) 16:9 Only File",

                CheckFileExists = true,
                CheckPathExists = true,

                FilterIndex = 2,
                RestoreDirectory = true,

                ReadOnlyChecked = true,
                ShowReadOnly = true
            };

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                source = new Bitmap(openFileDialog1.FileName);
            } else source = new Bitmap(1, 1);

            openFileDialog1 = new OpenFileDialog
            {
                Title = "Browse Image (1) File",

                CheckFileExists = true,
                CheckPathExists = true,

                FilterIndex = 2,
                RestoreDirectory = true,

                ReadOnlyChecked = true,
                ShowReadOnly = true
            };

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                source2 = new Bitmap(openFileDialog1.FileName);
            }
            else source2 = new Bitmap(1, 1);

            openFileDialog1 = new OpenFileDialog
            {
                Title = "Browse Image (3) File",

                CheckFileExists = true,
                CheckPathExists = true,

                FilterIndex = 2,
                RestoreDirectory = true,

                ReadOnlyChecked = true,
                ShowReadOnly = true
            };

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                source3 = new Bitmap(openFileDialog1.FileName);
            }

            openFileDialog1 = new OpenFileDialog
            {
                Title = "Browse spr_db File",

                CheckFileExists = true,
                CheckPathExists = true,

                FilterIndex = 2,
                RestoreDirectory = true,

                ReadOnlyChecked = true,
                ShowReadOnly = true
            };

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                spritedb.Load(openFileDialog1.FileName);
            }

            spritedb = sprselpvmerge.Make(spritedb, source, source2, source3, id);

            spritedb.Save(@"new_spr_db.bin");

            return;
        }
    }
}
